package com.example.myaptuselearing.bindview

import android.app.Activity
import com.example.myaptuselearing.annotation_introduce.BindViewRuntime
import java.util.*

/**
 * @author tgw
 * @date 2021/9/30
 * @describe
 */
object ButtonKnife {
    private const val bindAdapterActivity = "BindAdapterImp"

    //做了一个缓存，只有第一次bind时才通过反射创建对象
    fun bind(target: Activity) {
        var bindAdapter: BindAdapter<Activity>? = null
        try {
            val adapterClassName = target.javaClass.name+ bindAdapterActivity
            val aClass = Class.forName(adapterClassName)
            bindAdapter = aClass.newInstance() as BindAdapter<Activity>
        } catch (e: Exception) {
            e.printStackTrace()
        }
        //调用bind
        bindAdapter?.bind(target)
    }
}